package com.dstz.crm.core.manager.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dstz.base.api.query.QueryFilter;
import com.dstz.base.core.util.StringUtil;
import com.dstz.base.manager.impl.BaseManager;
import com.dstz.crm.core.dao.ProductDao;
import com.dstz.crm.core.manager.ProductManager;
import com.dstz.crm.core.model.Product;
import com.dstz.sys.api.model.IDataDict;
import com.dstz.sys.api.service.DataDictService;
/**
 * 案例 Manager处理实现类
 * @author aschs
 * @email aschs@qq.com
 * @time 2018-08-24 18:06:04
 */
@Service("productManager")
public class ProductManagerImpl extends BaseManager<String, Product> implements ProductManager{
	@Resource
	ProductDao productDao;
	@Resource
	DataDictService dataDictService;
	
	
	@Override
	public List<Product> query(QueryFilter queryFilter) {
		List<Product> query = dao.query(queryFilter);
		if(query!=null&&query.size()>0) {
			List<IDataDict> cplxList = dataDictService.getDictNodeList("cplx", false);
			List<IDataDict> cpztList = dataDictService.getDictNodeList("cpzt", false);
			for (Product product : query) {
				String type = product.getType();
				String state = product.getState();
				if(StringUtil.isNotEmpty(type)) {
					for (IDataDict iDataDict : cplxList) {
						if(type.equals(iDataDict.getKey())) {
							product.setTypeName(iDataDict.getName());
							break;
						}
					}
				}
				if(StringUtil.isNotEmpty(state)) {
					for (IDataDict iDataDict : cpztList) {
						if(state.equals(iDataDict.getKey())) {
							product.setStateName(iDataDict.getName());
							break;
						}
					}
				}
			}
		}
		
		
        return query;
    }
	
//	@Override
//	public Demo get(String entityId) {
//		Demo demo = super.get(entityId);
//		if(demo == null) return null;
//		
//		List<DemoSub> demoSublist = demoSubMananger.getByFk(entityId);
//		demo.setDemoSubList(demoSublist);
//		
//		return demo;
//	}
	
	
	

	/**
	 * URL 表单案例
	 */
//	@Override
//	public void saveDemoJson(ActionCmd actionCmd) {
//		String bizKey = actionCmd.getBusinessKey();
//		JSONObject object = actionCmd.getBusData();
//		Product demo = JSON.toJavaObject(object, Product.class);
//		
//		if(StringUtil.isEmpty(bizKey)) {
//			String id = IdUtil.getSuid();
//			actionCmd.setBusinessKey(id);
//			demo.setId(id);
//			productDao.create(demo);
//			
//			Map<String,Object> hashMap = new HashMap<>();
//			hashMap.put("startVariable", demo.getName());
//			//启动时候设置一些流程变量，请看 act_ru_variable 表、在整个流程声明周期您都可以使用该流程变量，可以用于分支判断等等
//			actionCmd.setActionVariables(hashMap);
//		}else {
//			productDao.update(demo);
//			Map<String,Object> hashMap = new HashMap<>();
//			hashMap.put("doTaskVariable", demo.getName() + "-" + actionCmd.getActionName());
//			actionCmd.setActionVariables(hashMap);
//		}
//	}
	
}
